package collection_try;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayListTest {
    public String reverseVowels(String s) {
        StringBuilder str = new StringBuilder(s);
        List<Integer> arr = new ArrayList<>();
        String vowels = "aeiouAEIOU";
        for(int i=0;i<s.length();i++){
            if(vowels.indexOf(s.charAt(i)) != -1){
                arr.add(i);
            }
        }
        int j=0;
        int k=arr.size()-1;
        while(j<k){
            char temp = str.charAt(arr.get(j));
            str.setCharAt(arr.get(j),str.charAt(arr.get(k)));
            str.setCharAt(arr.get(k),temp);
            j++;
            k--;
        }
        return str.toString();
    }

    public static void main(String[] args) {
        //List是接口，使用需要子类
        ArrayList<Integer> list = new ArrayList<>(9);
        list.addAll(Arrays.asList(4,7,8,-1));
        System.out.println("List init ====>>> "+list);
        String x = Integer.toBinaryString(2) + " " + Integer.toBinaryString(-2) + " " + Integer.toHexString(-2 >>> 2) + " " + Integer.toBinaryString(-2 >>> 2);
        System.out.println(x);
        //add(int index,E e)添加单个元素到指定下标
        list.add(1,5);
        System.out.println("List add(1,5):在下标为1的位置添加元素5"+list);
        //set(int index,E e)设置单个元素到指定下标
        list.set(4, 6);
        System.out.println("List set(1,6):在下标为1的位置设置元素6"+list);
        System.out.println(x);
        //get(int index)获取指定下标元素
        System.out.println("List get(1):获取下标为1的元素："+list.get(1));
        System.out.println(x);
        //remove(int index)移除指定下标元素
        list.remove(1);
        System.out.println("List remove(1):移除下标为1的元素："+list);
        list.add(12);
        System.out.println(list+" "+list.size());
        list.add(6);
        System.out.println("最后一个6:"+list.lastIndexOf(6));
        // listIterator 专门为list 遍历过程中修改元素或进行双向遍历，则应选择ListIterator
//        见"./ArrayListIterator_Iterator"
    }
}
